﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using System.IO;
using LibHuman;
namespace Human
{
	/// <summary>
	/// Summary description for frmDanhMucNgachCongChuc.
	/// </summary>
	public class frmDanhMucNgachCongChuc : System.Windows.Forms.Form
	{
		private AccessData  mDB=new AccessData();
        Language lan = new Language();
		private DataSet ds=new DataSet();
        string m_user = "";
		private System.Windows.Forms.TextBox txtMa;
		private System.Windows.Forms.TextBox txtTen;
		private System.Windows.Forms.TextBox txtb11;
		private System.Windows.Forms.TextBox txtb1;
		private System.Windows.Forms.TextBox txtb5;
		private System.Windows.Forms.TextBox txtb4;
		private System.Windows.Forms.TextBox txtb2;
		private System.Windows.Forms.TextBox txtb3;
		private System.Windows.Forms.TextBox txtb8;
		private System.Windows.Forms.TextBox txtb7;
		private System.Windows.Forms.TextBox txtb9;
		private System.Windows.Forms.TextBox txtb6;
        private System.Windows.Forms.TextBox txtb10;
        private System.Windows.Forms.TextBox txtb13;
		private System.Windows.Forms.TextBox txtb12;
		bool fthem=false;
		private System.Windows.Forms.TextBox txtma1;
        private DataGrid dgrDanhMucNgachCongChuc;
        private Label label1;
        private ComboBox cmbloaicc;
        private Button btn_them;
        private Button btn_sua;
        private Button btn_luu;
        private Button btn_boqua;
        private Button btn_xoa;
        private Button btn_thoat;
        private ComboBox cbo_nhomngach;
        private Label label2;
        private TextBox txt_stt;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmDanhMucNgachCongChuc()
		{
			InitializeComponent();
            lan.Read_Language_to_Xml(this.Name.ToString(), this);
            lan.Changelanguage_to_English(this.Name.ToString(), this);
            if (Screen.PrimaryScreen.WorkingArea.Width >= 1000)//
            {
                //+"\n"+Screen.PrimaryScreen.WorkingArea.Height.ToString());
                //this.MaximumSize=true;
                this.WindowState = FormWindowState.Normal;
                this.MaximizeBox = false;
            }
            else
            {
                //this.BackgroundImage = lbl800.Image;
                this.WindowState = FormWindowState.Maximized;
            }

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmDanhMucNgachCongChuc));
            this.txtMa = new System.Windows.Forms.TextBox();
            this.txtTen = new System.Windows.Forms.TextBox();
            this.txtb11 = new System.Windows.Forms.TextBox();
            this.txtb1 = new System.Windows.Forms.TextBox();
            this.txtb5 = new System.Windows.Forms.TextBox();
            this.txtb4 = new System.Windows.Forms.TextBox();
            this.txtb2 = new System.Windows.Forms.TextBox();
            this.txtb3 = new System.Windows.Forms.TextBox();
            this.txtb8 = new System.Windows.Forms.TextBox();
            this.txtb7 = new System.Windows.Forms.TextBox();
            this.txtb9 = new System.Windows.Forms.TextBox();
            this.txtb6 = new System.Windows.Forms.TextBox();
            this.txtb10 = new System.Windows.Forms.TextBox();
            this.txtb13 = new System.Windows.Forms.TextBox();
            this.txtb12 = new System.Windows.Forms.TextBox();
            this.txtma1 = new System.Windows.Forms.TextBox();
            this.dgrDanhMucNgachCongChuc = new System.Windows.Forms.DataGrid();
            this.label1 = new System.Windows.Forms.Label();
            this.cmbloaicc = new System.Windows.Forms.ComboBox();
            this.btn_them = new System.Windows.Forms.Button();
            this.btn_sua = new System.Windows.Forms.Button();
            this.btn_luu = new System.Windows.Forms.Button();
            this.btn_boqua = new System.Windows.Forms.Button();
            this.btn_xoa = new System.Windows.Forms.Button();
            this.btn_thoat = new System.Windows.Forms.Button();
            this.cbo_nhomngach = new System.Windows.Forms.ComboBox();
            this.label2 = new System.Windows.Forms.Label();
            this.txt_stt = new System.Windows.Forms.TextBox();
            ((System.ComponentModel.ISupportInitialize)(this.dgrDanhMucNgachCongChuc)).BeginInit();
            this.SuspendLayout();
            // 
            // txtMa
            // 
            this.txtMa.BackColor = System.Drawing.Color.White;
            this.txtMa.Location = new System.Drawing.Point(3, 470);
            this.txtMa.Name = "txtMa";
            this.txtMa.Size = new System.Drawing.Size(69, 20);
            this.txtMa.TabIndex = 0;
            this.txtMa.Validated += new System.EventHandler(this.txtMa_Validated);
            this.txtMa.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtMa_KeyDown);
            // 
            // txtTen
            // 
            this.txtTen.BackColor = System.Drawing.Color.White;
            this.txtTen.Location = new System.Drawing.Point(72, 470);
            this.txtTen.Name = "txtTen";
            this.txtTen.Size = new System.Drawing.Size(161, 20);
            this.txtTen.TabIndex = 1;
            this.txtTen.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtTen_KeyDown);
            // 
            // txtb11
            // 
            this.txtb11.BackColor = System.Drawing.Color.White;
            this.txtb11.Location = new System.Drawing.Point(582, 470);
            this.txtb11.Name = "txtb11";
            this.txtb11.Size = new System.Drawing.Size(35, 20);
            this.txtb11.TabIndex = 12;
            this.txtb11.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtb11_KeyDown);
            this.txtb11.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtb11_KeyPress);
            // 
            // txtb1
            // 
            this.txtb1.BackColor = System.Drawing.Color.White;
            this.txtb1.Location = new System.Drawing.Point(232, 470);
            this.txtb1.Name = "txtb1";
            this.txtb1.Size = new System.Drawing.Size(35, 20);
            this.txtb1.TabIndex = 2;
            this.txtb1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtb1_KeyDown);
            this.txtb1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtb1_KeyPress);
            // 
            // txtb5
            // 
            this.txtb5.BackColor = System.Drawing.Color.White;
            this.txtb5.Location = new System.Drawing.Point(372, 470);
            this.txtb5.Name = "txtb5";
            this.txtb5.Size = new System.Drawing.Size(35, 20);
            this.txtb5.TabIndex = 6;
            this.txtb5.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtb5_KeyDown);
            this.txtb5.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtb5_KeyPress);
            // 
            // txtb4
            // 
            this.txtb4.BackColor = System.Drawing.Color.White;
            this.txtb4.Location = new System.Drawing.Point(337, 470);
            this.txtb4.Name = "txtb4";
            this.txtb4.Size = new System.Drawing.Size(35, 20);
            this.txtb4.TabIndex = 5;
            this.txtb4.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtb4_KeyDown);
            this.txtb4.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtb4_KeyPress);
            // 
            // txtb2
            // 
            this.txtb2.BackColor = System.Drawing.Color.White;
            this.txtb2.Location = new System.Drawing.Point(267, 470);
            this.txtb2.Name = "txtb2";
            this.txtb2.Size = new System.Drawing.Size(35, 20);
            this.txtb2.TabIndex = 3;
            this.txtb2.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtb2_KeyDown);
            this.txtb2.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtb2_KeyPress);
            // 
            // txtb3
            // 
            this.txtb3.BackColor = System.Drawing.Color.White;
            this.txtb3.Location = new System.Drawing.Point(302, 470);
            this.txtb3.Name = "txtb3";
            this.txtb3.Size = new System.Drawing.Size(35, 20);
            this.txtb3.TabIndex = 4;
            this.txtb3.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtb3_KeyDown);
            this.txtb3.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtb3_KeyPress);
            // 
            // txtb8
            // 
            this.txtb8.BackColor = System.Drawing.Color.White;
            this.txtb8.Location = new System.Drawing.Point(477, 470);
            this.txtb8.Name = "txtb8";
            this.txtb8.Size = new System.Drawing.Size(35, 20);
            this.txtb8.TabIndex = 9;
            this.txtb8.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtb8_KeyDown);
            this.txtb8.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtb8_KeyPress);
            // 
            // txtb7
            // 
            this.txtb7.BackColor = System.Drawing.Color.White;
            this.txtb7.Location = new System.Drawing.Point(442, 470);
            this.txtb7.Name = "txtb7";
            this.txtb7.Size = new System.Drawing.Size(35, 20);
            this.txtb7.TabIndex = 8;
            this.txtb7.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtb7_KeyDown);
            this.txtb7.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtb7_KeyPress);
            // 
            // txtb9
            // 
            this.txtb9.BackColor = System.Drawing.Color.White;
            this.txtb9.Location = new System.Drawing.Point(512, 470);
            this.txtb9.Name = "txtb9";
            this.txtb9.Size = new System.Drawing.Size(35, 20);
            this.txtb9.TabIndex = 10;
            this.txtb9.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtb9_KeyDown);
            this.txtb9.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtb9_KeyPress);
            // 
            // txtb6
            // 
            this.txtb6.BackColor = System.Drawing.Color.White;
            this.txtb6.Location = new System.Drawing.Point(407, 470);
            this.txtb6.Name = "txtb6";
            this.txtb6.Size = new System.Drawing.Size(35, 20);
            this.txtb6.TabIndex = 7;
            this.txtb6.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtb6_KeyDown);
            this.txtb6.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtb6_KeyPress);
            // 
            // txtb10
            // 
            this.txtb10.BackColor = System.Drawing.Color.White;
            this.txtb10.Location = new System.Drawing.Point(547, 470);
            this.txtb10.Name = "txtb10";
            this.txtb10.Size = new System.Drawing.Size(35, 20);
            this.txtb10.TabIndex = 11;
            this.txtb10.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtb10_KeyDown);
            this.txtb10.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtb10_KeyPress);
            // 
            // txtb13
            // 
            this.txtb13.BackColor = System.Drawing.Color.White;
            this.txtb13.Location = new System.Drawing.Point(652, 470);
            this.txtb13.Name = "txtb13";
            this.txtb13.Size = new System.Drawing.Size(55, 20);
            this.txtb13.TabIndex = 14;
            this.txtb13.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtb13_KeyDown);
            // 
            // txtb12
            // 
            this.txtb12.BackColor = System.Drawing.Color.White;
            this.txtb12.Location = new System.Drawing.Point(617, 470);
            this.txtb12.Name = "txtb12";
            this.txtb12.Size = new System.Drawing.Size(35, 20);
            this.txtb12.TabIndex = 13;
            this.txtb12.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtb12_KeyDown);
            this.txtb12.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtb12_KeyPress);
            // 
            // txtma1
            // 
            this.txtma1.BackColor = System.Drawing.Color.White;
            this.txtma1.Enabled = false;
            this.txtma1.Location = new System.Drawing.Point(318, 395);
            this.txtma1.Name = "txtma1";
            this.txtma1.Size = new System.Drawing.Size(69, 20);
            this.txtma1.TabIndex = 51;
            // 
            // dgrDanhMucNgachCongChuc
            // 
            this.dgrDanhMucNgachCongChuc.AlternatingBackColor = System.Drawing.Color.Lavender;
            this.dgrDanhMucNgachCongChuc.BackColor = System.Drawing.Color.WhiteSmoke;
            this.dgrDanhMucNgachCongChuc.BackgroundColor = System.Drawing.SystemColors.Control;
            this.dgrDanhMucNgachCongChuc.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.dgrDanhMucNgachCongChuc.CaptionBackColor = System.Drawing.Color.LightSteelBlue;
            this.dgrDanhMucNgachCongChuc.CaptionForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMucNgachCongChuc.CaptionText = "Danh mục ngạch công chức";
            this.dgrDanhMucNgachCongChuc.CaptionVisible = false;
            this.dgrDanhMucNgachCongChuc.DataMember = "";
            this.dgrDanhMucNgachCongChuc.FlatMode = true;
            this.dgrDanhMucNgachCongChuc.Font = new System.Drawing.Font("Tahoma", 8F);
            this.dgrDanhMucNgachCongChuc.ForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMucNgachCongChuc.GridLineColor = System.Drawing.Color.Gainsboro;
            this.dgrDanhMucNgachCongChuc.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;
            this.dgrDanhMucNgachCongChuc.HeaderBackColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMucNgachCongChuc.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
            this.dgrDanhMucNgachCongChuc.HeaderForeColor = System.Drawing.Color.WhiteSmoke;
            this.dgrDanhMucNgachCongChuc.LinkColor = System.Drawing.Color.Teal;
            this.dgrDanhMucNgachCongChuc.Location = new System.Drawing.Point(2, 4);
            this.dgrDanhMucNgachCongChuc.Name = "dgrDanhMucNgachCongChuc";
            this.dgrDanhMucNgachCongChuc.ParentRowsBackColor = System.Drawing.Color.Gainsboro;
            this.dgrDanhMucNgachCongChuc.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMucNgachCongChuc.RowHeaderWidth = 15;
            this.dgrDanhMucNgachCongChuc.SelectionBackColor = System.Drawing.Color.CadetBlue;
            this.dgrDanhMucNgachCongChuc.SelectionForeColor = System.Drawing.Color.WhiteSmoke;
            this.dgrDanhMucNgachCongChuc.Size = new System.Drawing.Size(780, 460);
            this.dgrDanhMucNgachCongChuc.TabIndex = 50;
            this.dgrDanhMucNgachCongChuc.CurrentCellChanged += new System.EventHandler(this.dgrDanhMucNgachCongChuc_CurrentCellChanged);
            this.dgrDanhMucNgachCongChuc.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dgrDanhMucNgachCongChuc_KeyDown);
            // 
            // label1
            // 
            this.label1.ForeColor = System.Drawing.Color.DarkBlue;
            this.label1.Location = new System.Drawing.Point(441, 499);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(71, 13);
            this.label1.TabIndex = 53;
            this.label1.Text = "Nhóm ngạch:";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // cmbloaicc
            // 
            this.cmbloaicc.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cmbloaicc.FormattingEnabled = true;
            this.cmbloaicc.Location = new System.Drawing.Point(707, 470);
            this.cmbloaicc.Name = "cmbloaicc";
            this.cmbloaicc.Size = new System.Drawing.Size(75, 21);
            this.cmbloaicc.TabIndex = 15;
            this.cmbloaicc.KeyDown += new System.Windows.Forms.KeyEventHandler(this.cmbloaicc_KeyDown);
            // 
            // btn_them
            // 
            this.btn_them.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_them.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_them.Image = global::Human.Properties.Resources.add;
            this.btn_them.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_them.Location = new System.Drawing.Point(152, 529);
            this.btn_them.Name = "btn_them";
            this.btn_them.Size = new System.Drawing.Size(60, 28);
            this.btn_them.TabIndex = 54;
            this.btn_them.Text = "&Thêm";
            this.btn_them.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btn_them.UseVisualStyleBackColor = true;
            this.btn_them.Click += new System.EventHandler(this.btn_them_Click);
            this.btn_them.KeyDown += new System.Windows.Forms.KeyEventHandler(this.btn_them_KeyDown);
            // 
            // btn_sua
            // 
            this.btn_sua.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_sua.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_sua.Image = global::Human.Properties.Resources.quick_edit;
            this.btn_sua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_sua.Location = new System.Drawing.Point(218, 529);
            this.btn_sua.Name = "btn_sua";
            this.btn_sua.Size = new System.Drawing.Size(60, 28);
            this.btn_sua.TabIndex = 55;
            this.btn_sua.Text = "&Sửa";
            this.btn_sua.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btn_sua.UseVisualStyleBackColor = true;
            this.btn_sua.Click += new System.EventHandler(this.btn_sua_Click);
            this.btn_sua.KeyDown += new System.Windows.Forms.KeyEventHandler(this.btn_sua_KeyDown);
            // 
            // btn_luu
            // 
            this.btn_luu.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_luu.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_luu.Image = global::Human.Properties.Resources.save;
            this.btn_luu.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_luu.Location = new System.Drawing.Point(284, 529);
            this.btn_luu.Name = "btn_luu";
            this.btn_luu.Size = new System.Drawing.Size(60, 28);
            this.btn_luu.TabIndex = 56;
            this.btn_luu.Text = "&Lưu";
            this.btn_luu.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btn_luu.UseVisualStyleBackColor = true;
            this.btn_luu.Click += new System.EventHandler(this.btn_luu_Click);
            this.btn_luu.KeyDown += new System.Windows.Forms.KeyEventHandler(this.btn_luu_KeyDown);
            // 
            // btn_boqua
            // 
            this.btn_boqua.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_boqua.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_boqua.Image = global::Human.Properties.Resources.t_boqua1;
            this.btn_boqua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_boqua.Location = new System.Drawing.Point(350, 529);
            this.btn_boqua.Name = "btn_boqua";
            this.btn_boqua.Size = new System.Drawing.Size(70, 28);
            this.btn_boqua.TabIndex = 57;
            this.btn_boqua.Text = "&Bỏ qua";
            this.btn_boqua.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btn_boqua.UseVisualStyleBackColor = true;
            this.btn_boqua.Click += new System.EventHandler(this.btn_boqua_Click);
            // 
            // btn_xoa
            // 
            this.btn_xoa.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_xoa.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_xoa.Image = global::Human.Properties.Resources.delete_enabled;
            this.btn_xoa.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_xoa.Location = new System.Drawing.Point(426, 529);
            this.btn_xoa.Name = "btn_xoa";
            this.btn_xoa.Size = new System.Drawing.Size(60, 28);
            this.btn_xoa.TabIndex = 58;
            this.btn_xoa.Text = "&Xóa";
            this.btn_xoa.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btn_xoa.UseVisualStyleBackColor = true;
            this.btn_xoa.Click += new System.EventHandler(this.btn_xoa_Click);
            // 
            // btn_thoat
            // 
            this.btn_thoat.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_thoat.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_thoat.Image = global::Human.Properties.Resources.close_r;
            this.btn_thoat.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_thoat.Location = new System.Drawing.Point(492, 529);
            this.btn_thoat.Name = "btn_thoat";
            this.btn_thoat.Size = new System.Drawing.Size(60, 28);
            this.btn_thoat.TabIndex = 59;
            this.btn_thoat.Text = "&Thoát";
            this.btn_thoat.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btn_thoat.UseVisualStyleBackColor = true;
            this.btn_thoat.Click += new System.EventHandler(this.btn_thoat_Click);
            // 
            // cbo_nhomngach
            // 
            this.cbo_nhomngach.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cbo_nhomngach.FormattingEnabled = true;
            this.cbo_nhomngach.Location = new System.Drawing.Point(518, 495);
            this.cbo_nhomngach.Name = "cbo_nhomngach";
            this.cbo_nhomngach.Size = new System.Drawing.Size(165, 21);
            this.cbo_nhomngach.TabIndex = 16;
            this.cbo_nhomngach.KeyDown += new System.Windows.Forms.KeyEventHandler(this.cbo_nhomngach_KeyDown);
            // 
            // label2
            // 
            this.label2.ForeColor = System.Drawing.Color.DarkBlue;
            this.label2.Location = new System.Drawing.Point(691, 500);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(31, 13);
            this.label2.TabIndex = 53;
            this.label2.Text = "STT:";
            this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // txt_stt
            // 
            this.txt_stt.Location = new System.Drawing.Point(728, 496);
            this.txt_stt.Name = "txt_stt";
            this.txt_stt.Size = new System.Drawing.Size(54, 20);
            this.txt_stt.TabIndex = 17;
            this.txt_stt.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txt_stt_KeyDown);
            this.txt_stt.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_stt_KeyPress);
            // 
            // frmDanhMucNgachCongChuc
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(788, 569);
            this.Controls.Add(this.txt_stt);
            this.Controls.Add(this.cbo_nhomngach);
            this.Controls.Add(this.btn_thoat);
            this.Controls.Add(this.btn_xoa);
            this.Controls.Add(this.btn_boqua);
            this.Controls.Add(this.btn_luu);
            this.Controls.Add(this.btn_sua);
            this.Controls.Add(this.btn_them);
            this.Controls.Add(this.cmbloaicc);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.txtMa);
            this.Controls.Add(this.dgrDanhMucNgachCongChuc);
            this.Controls.Add(this.txtTen);
            this.Controls.Add(this.txtb11);
            this.Controls.Add(this.txtb1);
            this.Controls.Add(this.txtb5);
            this.Controls.Add(this.txtb4);
            this.Controls.Add(this.txtb2);
            this.Controls.Add(this.txtb3);
            this.Controls.Add(this.txtb8);
            this.Controls.Add(this.txtb7);
            this.Controls.Add(this.txtb9);
            this.Controls.Add(this.txtb6);
            this.Controls.Add(this.txtb10);
            this.Controls.Add(this.txtb13);
            this.Controls.Add(this.txtb12);
            this.Controls.Add(this.txtma1);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Name = "frmDanhMucNgachCongChuc";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Danh mục ngạch công chức";
            this.Load += new System.EventHandler(this.frmDanhMucNgachCongChuc_Load);
            ((System.ComponentModel.ISupportInitialize)(this.dgrDanhMucNgachCongChuc)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		private void butThoat_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
		private void load_datagrid() 	
		{
			DataSet ds1=new DataSet();
			ds1=mDB.get_data("SELECT ma1,diengiai,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,ma,loaingach,nhomngach,stt FROM "+m_user+".mangach order by stt");
            //ds1.WriteXml(@"xml\ngachcc.xml", XmlWriteMode.WriteSchema);
			
			dgrDanhMucNgachCongChuc.DataSource=null;
			dgrDanhMucNgachCongChuc.TableStyles.Clear();
			DataGridTableStyle ts = new DataGridTableStyle();
            ts.MappingName = ds1.Tables[0].TableName;
		
			ts.AlternatingBackColor = Color.Beige;
			ts.BackColor = Color.GhostWhite;
			ts.ForeColor = Color.MidnightBlue;
			ts.GridLineColor = Color.RoyalBlue;
			ts.HeaderBackColor = Color.MidnightBlue;
			ts.HeaderForeColor = Color.Lavender;
			ts.SelectionBackColor = Color.Teal;
			ts.SelectionForeColor = Color.PaleGreen;
			
			DataGridTextBoxColumn TextCol1=new DataGridTextBoxColumn();
			TextCol1.MappingName = "ma1";
			TextCol1.HeaderText = lan.Change_language_MessageText("Mã");
			TextCol1.Width = 55;
			TextCol1.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol1);
			dgrDanhMucNgachCongChuc.TableStyles.Add(ts);
		
			DataGridTextBoxColumn TextCol2=new DataGridTextBoxColumn();
			TextCol2.MappingName = "diengiai";
			TextCol2.HeaderText = lan.Change_language_MessageText("Ngạch công chức");
			TextCol2.Width = 165;
			TextCol2.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol2);
			dgrDanhMucNgachCongChuc.TableStyles.Add(ts);

			DataGridTextBoxColumn TextCol3=new DataGridTextBoxColumn();
			TextCol3.MappingName = "b1";
			TextCol3.HeaderText = lan.Change_language_MessageText("Bậc 1");
			TextCol3.Width = 35;
			TextCol3.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol3);
			dgrDanhMucNgachCongChuc.TableStyles.Add(ts);
		 			 
			DataGridTextBoxColumn TextCol4=new DataGridTextBoxColumn();
			TextCol4.MappingName = "b2";
			TextCol4.HeaderText = "2";
			TextCol4.Width = 35;
			TextCol4.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol4);
			dgrDanhMucNgachCongChuc.TableStyles.Add(ts);
			ts.DataGrid.DataSource=ds1.Tables[0]; 

			DataGridTextBoxColumn TextCol5=new DataGridTextBoxColumn();
			TextCol5.MappingName = "b3";
			TextCol5.HeaderText = "3";
			TextCol5.Width = 35;
			TextCol5.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol5);
			
			DataGridTextBoxColumn TextCol6=new DataGridTextBoxColumn();
			TextCol6.MappingName = "b4";
			TextCol6.HeaderText = "4";
			TextCol6.Width = 35;
			TextCol6.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol6);
			
			DataGridTextBoxColumn TextCol7=new DataGridTextBoxColumn();
			TextCol7.MappingName = "b5";
			TextCol7.HeaderText = "5";
			TextCol7.Width = 35;
			TextCol7.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol7);
			
			DataGridTextBoxColumn TextCol8=new DataGridTextBoxColumn();
			TextCol8.MappingName = "b6";
			TextCol8.HeaderText = "6";
			TextCol8.Width = 35;
			TextCol8.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol8);

			DataGridTextBoxColumn TextCol9=new DataGridTextBoxColumn();
			TextCol9.MappingName = "b7";
			TextCol9.HeaderText = "7";
			TextCol9.Width = 35;
			TextCol9.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol9);

			DataGridTextBoxColumn TextCol10=new DataGridTextBoxColumn();
			TextCol10.MappingName = "b8";
			TextCol10.HeaderText = "8";
			TextCol10.Width = 35;
			TextCol10.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol10);
			
			DataGridTextBoxColumn TextCol11=new DataGridTextBoxColumn();
			TextCol11.MappingName = "b9";
			TextCol11.HeaderText = "9";
			TextCol11.Width = 35;
			TextCol11.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol11);

			DataGridTextBoxColumn TextCol12=new DataGridTextBoxColumn();
			TextCol12.MappingName = "b10";
			TextCol12.HeaderText = "10";
			TextCol12.Width = 35;
			TextCol12.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol12);

			DataGridTextBoxColumn TextCol13=new DataGridTextBoxColumn();
			TextCol13.MappingName = "b11";
			TextCol13.HeaderText = "11";
			TextCol13.Width = 35;
			TextCol13.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol13);

			DataGridTextBoxColumn TextCol14=new DataGridTextBoxColumn();
			TextCol14.MappingName = "b12";
			TextCol14.HeaderText = "12";
			TextCol14.Width = 35;
			TextCol14.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol14);

			DataGridTextBoxColumn TextCol15=new DataGridTextBoxColumn();
			TextCol15.MappingName = "ma";
			TextCol15.HeaderText = "ma";
			TextCol15.Width = 55;
			TextCol15.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol15);

			DataGridTextBoxColumn TextCol16=new DataGridTextBoxColumn();
			TextCol16.MappingName = "loaingach";
			TextCol16.HeaderText = lan.Change_language_MessageText("loai");
			TextCol16.Width = 35;
			TextCol16.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol16);

            DataGridTextBoxColumn TextCol17 = new DataGridTextBoxColumn();
            TextCol17.MappingName = "nhomngach";
            TextCol17.HeaderText = "nhomngach";
            TextCol17.Width = 35;
            TextCol17.Alignment = HorizontalAlignment.Left;
            ts.GridColumnStyles.Add(TextCol17);

            DataGridTextBoxColumn TextCol18 = new DataGridTextBoxColumn();
            TextCol18.MappingName = "stt";
            TextCol18.HeaderText = "stt";
            TextCol18.Width = 35;
            TextCol18.Alignment = HorizontalAlignment.Left;
            ts.GridColumnStyles.Add(TextCol18);

			dgrDanhMucNgachCongChuc.TableStyles.Add(ts);

			CurrencyManager cm = (CurrencyManager) BindingContext[dgrDanhMucNgachCongChuc.DataSource,dgrDanhMucNgachCongChuc.DataMember];
			DataView dv = (DataView) cm.List;
			dv.AllowDelete=false;
			dv.AllowNew=false;
			dv.AllowEdit=false;
		}

		private void dgrDanhMucNgachCongChuc_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode.ToString() == "Enter")
				SendKeys.Send("{Tab}");
		}

		private void frmDanhMucNgachCongChuc_Load(object sender, System.EventArgs e)
		{
            m_user = mDB.user;
            load_datagrid();
			Ena_control(true);
			refresh_Text();
			Ena_textbox(false);
			btn_them.Focus();
            loai_loaingach();
            load_nhomngach();
		}
        private void load_nhomngach()
        {
            cbo_nhomngach.DataSource = mDB.get_nhomngach().Tables[0];
            cbo_nhomngach.ValueMember = "manhom";
            cbo_nhomngach.DisplayMember = "tennhom";
            cbo_nhomngach.SelectedIndex = -1;
        }
        private string load_tenngach(string nhomngach)
        {            
            return mDB.get_nhomngach(nhomngach).Tables[0].Rows[0]["tennhom"].ToString();             
        }
        private void loai_loaingach()
        {
            cmbloaicc.DataSource = mDB.get_loaingach().Tables[0];
            cmbloaicc.DisplayMember = "loaingach";
            cmbloaicc.ValueMember = "loaingach";
            cmbloaicc.SelectedIndex = -1;
        }
		private string kiemtra_ma(string ma)
		{	
			string m_ma="",s="",m1="",m2="",kytu="";
			string[] arr_kytu= new string[]{"b","c","d","e","f"};
			// Ma: truong dữ liệu không trùng nhau, còn ma1 cho phep trùng 
			DataTable dt1	 = new DataTable();
            dt1 = mDB.get_data("select ma,ma1 from " + mDB.user + ".mangach where ma1='" + ma + "' order by stt desc LIMIT 1").Tables[0];
			if (dt1.Rows.Count==0)
				m_ma=ma;
			int vt=-1,vt1=-1;
            bool co = false;
			foreach(DataRow r in dt1.Rows )
			{
				s=r["ma1"].ToString();
				vt=s.IndexOf(".");
				if (s==ma)
                {
                    m1 = s.Substring(0, vt);
                    m2 = s.Substring(vt + 1);
                    for (int x = 0; x < arr_kytu.Length; x++) 
                    {
                        kytu = arr_kytu[x];
                        if (m1.IndexOf(kytu) >= 0)
                        {
                            m_ma = m1.Substring(0,m1.IndexOf(kytu)) + arr_kytu[x+1] + "." + m2;
                            if (mDB.get_data("select ma,ma1 from " + mDB.user + ".mangach where ma='" + m_ma + "' order by ma desc LIMIT 1").Tables[0].Rows.Count>0)
                                m_ma = m1.Substring(0, m1.IndexOf(kytu)) + arr_kytu[x + 2] + "." + m2;
                            co = true;
                            break;
                        }
                    }
                    if (co==false)
                        m_ma = m1 + "b" + "." + m2;
                }
				else
				{
					m1=s.Substring(0,vt);
					m2=s.Substring(vt+1);
					for(int i=0;i<=arr_kytu.Length-1;i++)
					{
						vt1= m1.IndexOf(arr_kytu[i].ToString());
						if (vt1==-1)
						{
							m1=m1.Substring(0,m1.Length-1)+arr_kytu[i].ToString();	
							m_ma=m1+"."+m2;
							break;
						}
					}

				}
			}
			return m_ma;
 
		}
		private void butThem_Click(object sender, System.EventArgs e)
		{
			try
			{				
				int i=dgrDanhMucNgachCongChuc.CurrentCell.RowNumber;
				if(i<0)  
					i=dgrDanhMucNgachCongChuc.CurrentCell.RowNumber;
				if(i==dgrDanhMucNgachCongChuc.CurrentCell.RowNumber) 
				{								
									
					string t="";
					string m="",m1="",loai="",nhomngach="";
					decimal n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,stt;
					n1=0;n2=0;n3=0;n4=0;n5=0;n6=0;n7=0;n8=0;n9=0;n10=0;
					n11=0;n12=0;stt=0;
					
					if(dgrDanhMucNgachCongChuc[i,0].ToString().Length<=7)
					{
						if(dgrDanhMucNgachCongChuc[i,1].ToString().Length<=50)
						{
							if(!kiemtra())return;
							t=dgrDanhMucNgachCongChuc[i,1].ToString().Trim();					
							m=dgrDanhMucNgachCongChuc[i,0].ToString().Trim();					
							n1=(dgrDanhMucNgachCongChuc[i,2].ToString().Trim()=="")?0:decimal.Parse(dgrDanhMucNgachCongChuc[i,2].ToString().Trim());
							n2=(dgrDanhMucNgachCongChuc[i,3].ToString().Trim()=="")?0:decimal.Parse(dgrDanhMucNgachCongChuc[i,3].ToString().Trim());
							n3=(dgrDanhMucNgachCongChuc[i,4].ToString().Trim()=="")?0:decimal.Parse(dgrDanhMucNgachCongChuc[i,4].ToString().Trim());
							n4=(dgrDanhMucNgachCongChuc[i,5].ToString().Trim()=="")?0:decimal.Parse(dgrDanhMucNgachCongChuc[i,5].ToString().Trim());
							n5=(dgrDanhMucNgachCongChuc[i,6].ToString().Trim()=="")?0:decimal.Parse(dgrDanhMucNgachCongChuc[i,6].ToString().Trim());
							n6=(dgrDanhMucNgachCongChuc[i,7].ToString().Trim()=="")?0:decimal.Parse(dgrDanhMucNgachCongChuc[i,7].ToString().Trim());
							n7=(dgrDanhMucNgachCongChuc[i,8].ToString().Trim()=="")?0:decimal.Parse(dgrDanhMucNgachCongChuc[i,8].ToString().Trim());
							n8=(dgrDanhMucNgachCongChuc[i,9].ToString().Trim()=="")?0:decimal.Parse(dgrDanhMucNgachCongChuc[i,9].ToString().Trim());
							n9=(dgrDanhMucNgachCongChuc[i,10].ToString().Trim()=="")?0:decimal.Parse(dgrDanhMucNgachCongChuc[i,10].ToString().Trim());
							n10=(dgrDanhMucNgachCongChuc[i,11].ToString().Trim()=="")?0:decimal.Parse(dgrDanhMucNgachCongChuc[i,11].ToString().Trim());
							n11=(dgrDanhMucNgachCongChuc[i,12].ToString().Trim()=="")?0:decimal.Parse(dgrDanhMucNgachCongChuc[i,12].ToString().Trim());
							n12=(dgrDanhMucNgachCongChuc[i,13].ToString().Trim()=="")?0:decimal.Parse(dgrDanhMucNgachCongChuc[i,13].ToString().Trim());
                            stt =(dgrDanhMucNgachCongChuc[i,17].ToString().Trim()=="")?0:decimal.Parse(dgrDanhMucNgachCongChuc[i,17].ToString().Trim());
                            m1 = dgrDanhMucNgachCongChuc[i, 14].ToString().Trim();
                            loai= dgrDanhMucNgachCongChuc[i,15].ToString().Trim();
                            nhomngach = dgrDanhMucNgachCongChuc[i,16].ToString().Trim();


                            mDB.Execute_data("INSERT INTO " + mDB.user + ".mangach(ma,diengiai,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,ma1,loaingach,nhomngach) VALUES ('" + dgrDanhMucNgachCongChuc[i, 0].ToString().Trim() + "','" + t.Trim() + "'," + n1 + "," + n2 + "," + n3 + "," + n4 + "," + n5 + "," + n6 + "," + n7 + "," + n8 + "," + n9 + "," + n10 + "," + n11 + "," + n12 + ",'" + dgrDanhMucNgachCongChuc[i, 14].ToString().Trim() + "','" + dgrDanhMucNgachCongChuc[i, 15].ToString().Trim() + "','" + dgrDanhMucNgachCongChuc[i, 16].ToString().Trim() + "',"+stt+")");	

						}
					}	
					else
					{
						MessageBox.Show(lan.Change_language_MessageText("Mã ngạch công chức tối đa bằng 7 ký tự"),AccessData.Msg);
					}
					load_datagrid();
				}
			}
			catch
			{
				MessageBox.Show(lan.Change_language_MessageText("Dữ liệu không hợp lệ!"),AccessData.Msg);
				load_datagrid();
			}		
		}
		private bool kiemtra()
		{
            
            if(mDB.get_data("select ma from "+m_user+".mangach where ma='"+txtMa.Text.Trim()+"'").Tables[0].Rows.Count!=0)
			{	
				MessageBox.Show(lan.Change_language_MessageText("Mã ngạch bị trùng.Yêu cầu nhập mã khác!"),AccessData.Msg);
				return false;
			}
			
			if(txtMa.Text.IndexOf(",")>0)
			{
				MessageBox.Show(lan.Change_language_MessageText("Mã ngạch công chức không được có dấu phẩy!"),AccessData.Msg);			
				return false;
			}
			if(txtMa.Text.Trim().Length>7)
			{				
				MessageBox.Show(lan.Change_language_MessageText("Mã ngạch công chức tối đa bằng 7 ký tự"),AccessData.Msg);
				return false;
			}
			return true;
		}
		private void butHuy_Click(object sender, System.EventArgs e)
		{
			try
			{	
					int i=dgrDanhMucNgachCongChuc.CurrentCell.RowNumber;
					if(i<0)  
						i=dgrDanhMucNgachCongChuc.CurrentCell.RowNumber;
					if(i==dgrDanhMucNgachCongChuc.CurrentCell.RowNumber) 
					{						
						string t="";
						string m="";
						DialogResult dr = MessageBox.Show(lan.Change_language_MessageText("Đồng ý huỷ ngạch công chức này?"),AccessData.Msg,MessageBoxButtons.YesNo);			
						if(dr == DialogResult.Yes) 			
						{
								t=dgrDanhMucNgachCongChuc[i,1].ToString().Trim();					
								m=dgrDanhMucNgachCongChuc[i,0].ToString().Trim();												
								DataSet ds1=new DataSet();
								mDB.Execute_data ("DELETE * FROM mangach WHERE ma='"+m.Trim()+"' and diengiai='"+t.Trim()+"'");	
						load_datagrid();
					}
				}
			}
			catch
			{				
				load_datagrid();
			}		
		}

		private void btnsua_Click(object sender, System.EventArgs e)
		{
			try
			{				
				int i=dgrDanhMucNgachCongChuc.CurrentCell.RowNumber;
				if(i<0)  
					i=dgrDanhMucNgachCongChuc.CurrentCell.RowNumber;
				if(i==dgrDanhMucNgachCongChuc.CurrentCell.RowNumber) 
				{								
									
					string t="";
					string m="",m1="",loai="",nhomngach="";
					decimal n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,stt;
					n1=0;n2=0;n3=0;n4=0;n5=0;n6=0;n7=0;n8=0;n9=0;n10=0;
                    n11 = 0; n12 = 0; stt = 0;
					
					if(dgrDanhMucNgachCongChuc[i,0].ToString().Length<=6)
					{
						if(dgrDanhMucNgachCongChuc[i,1].ToString().Length<=50)
						{							
							t=dgrDanhMucNgachCongChuc[i,1].ToString().Trim();					
							m=dgrDanhMucNgachCongChuc[i,0].ToString().Trim();					
							n1=decimal.Parse(dgrDanhMucNgachCongChuc[i,2].ToString().Trim());
							n2=decimal.Parse(dgrDanhMucNgachCongChuc[i,3].ToString().Trim());
							n3=decimal.Parse(dgrDanhMucNgachCongChuc[i,4].ToString().Trim());
							n4=decimal.Parse(dgrDanhMucNgachCongChuc[i,5].ToString().Trim());
							n5=decimal.Parse(dgrDanhMucNgachCongChuc[i,6].ToString().Trim());
							n6=decimal.Parse(dgrDanhMucNgachCongChuc[i,7].ToString().Trim());
							n7=decimal.Parse(dgrDanhMucNgachCongChuc[i,8].ToString().Trim());
							n8=decimal.Parse(dgrDanhMucNgachCongChuc[i,9].ToString().Trim());
							n9=decimal.Parse(dgrDanhMucNgachCongChuc[i,10].ToString().Trim());
							n10=decimal.Parse(dgrDanhMucNgachCongChuc[i,11].ToString().Trim());
							n11=decimal.Parse(dgrDanhMucNgachCongChuc[i,12].ToString().Trim());
							n12=decimal.Parse(dgrDanhMucNgachCongChuc[i,13].ToString().Trim());
                            stt = decimal.Parse(dgrDanhMucNgachCongChuc[i, 17].ToString().Trim());
                            m1 = dgrDanhMucNgachCongChuc[i, 14].ToString().Trim();
                            loai = dgrDanhMucNgachCongChuc[i, 15].ToString().Trim();
                            nhomngach = dgrDanhMucNgachCongChuc[i, 16].ToString().Trim();
							mDB.Execute_data("update mangach set diengiai='"+t+"',b1="+n1+",b2="+n2+",b3="+n3+",b4="+n4+",b5="+n5+",b6="+n6+",b7="+n7+",b8="+n8+",b9="+n9+",b10="+n10+",b11="+n11+",b12="+n12+",ma1='"+m1.Trim()+"',loaingach='"+loai+"',nhomngach='"+nhomngach+"',stt="+stt+" where ma='"+m+"'");
						}
					}	
					load_datagrid();
				}
			}
			catch
			{
				MessageBox.Show(lan.Change_language_MessageText("Dữ liệu không hợp lệ!"),AccessData.Msg);
				load_datagrid();
			}	
		}
	
		private void Ena_control(bool ena)
		{
			btn_them.Enabled=ena;
			btn_sua.Enabled=ena;
			btn_luu.Enabled=!ena;
			btn_boqua.Enabled=!ena;
			btn_xoa.Enabled=ena;
			btn_thoat.Enabled=ena;
		}
		private void Ena_textbox(bool ena)
		{			
			txtMa.Enabled=ena;
			txtTen.Enabled=ena;
			txtb1.Enabled=ena;
			txtb2.Enabled=ena;
			txtb3.Enabled=ena;
			txtb4.Enabled=ena;
			txtb5.Enabled=ena;
			txtb6.Enabled=ena;
			txtb7.Enabled=ena;
			txtb8.Enabled=ena;
			txtb9.Enabled=ena;
			txtb10.Enabled=ena;
			txtb11.Enabled=ena;
			txtb12.Enabled=ena;
			txtb13.Enabled=ena;		
            cmbloaicc.Enabled = ena;
            cbo_nhomngach.Enabled = ena;
            txt_stt.Enabled = ena;
		}
		private void clear_Text()
		{			
			txtMa.Clear();
			txtTen.Clear();
			txtb1.Clear();
			txtb2.Clear();
			txtb3.Clear();
			txtb4.Clear();
			txtb5.Clear();
			txtb6.Clear();
			txtb7.Clear();
			txtb8.Clear();
			txtb9.Clear();
			txtb10.Clear();
			txtb11.Clear();
			txtb12.Clear();
			txtb13.Clear();		
            cmbloaicc.SelectedIndex = -1;
            cbo_nhomngach.SelectedIndex = -1;
            txt_stt.Text = "";
		}
		private void refresh_Text()
		{
			int i=dgrDanhMucNgachCongChuc.CurrentRowIndex;
			if(i>=0)
			{
				txtMa.Text=dgrDanhMucNgachCongChuc[i,0].ToString();
				txtTen.Text=dgrDanhMucNgachCongChuc[i,1].ToString();
				txtb1.Text=dgrDanhMucNgachCongChuc[i,2].ToString();
				txtb2.Text=dgrDanhMucNgachCongChuc[i,3].ToString();
				txtb3.Text=dgrDanhMucNgachCongChuc[i,4].ToString();
				txtb4.Text=dgrDanhMucNgachCongChuc[i,5].ToString();
				txtb5.Text=dgrDanhMucNgachCongChuc[i,6].ToString();
				txtb6.Text=dgrDanhMucNgachCongChuc[i,7].ToString();
				txtb7.Text=dgrDanhMucNgachCongChuc[i,8].ToString();
				txtb8.Text=dgrDanhMucNgachCongChuc[i,9].ToString();
				txtb9.Text=dgrDanhMucNgachCongChuc[i,10].ToString();
				txtb10.Text=dgrDanhMucNgachCongChuc[i,11].ToString();
				txtb11.Text=dgrDanhMucNgachCongChuc[i,12].ToString();
				txtb12.Text=dgrDanhMucNgachCongChuc[i,13].ToString();
				txtb13.Text=dgrDanhMucNgachCongChuc[i,14].ToString();
				cmbloaicc.Text=dgrDanhMucNgachCongChuc[i,15].ToString();
                txt_stt.Text = dgrDanhMucNgachCongChuc[i, 17].ToString();
                string nhomngach = dgrDanhMucNgachCongChuc[i, 16].ToString();
                if (nhomngach != "")
                {
                    cbo_nhomngach.Text = load_tenngach(dgrDanhMucNgachCongChuc[i, 16].ToString());
                }
                else
                {
                    cbo_nhomngach.SelectedValue = -1;
                }

				Ena_textbox(false);
			}
		}

		private void txtMa_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
            if (e.KeyCode == Keys.Enter)
            {
                SendKeys.Send("{Tab}");
                txtb13.Text = txtMa.Text;
            }

		}

		private void txtTen_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Enter)
				SendKeys.Send("{Tab}");
		}

		private void txtb1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
            if (e.KeyCode == Keys.Enter)
				SendKeys.Send("{Tab}");
		}

		private void txtb2_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
            if (e.KeyCode == Keys.Enter)
				SendKeys.Send("{Tab}");
		}

		private void txtb3_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
            if (e.KeyCode == Keys.Enter)
				SendKeys.Send("{Tab}");
		}

		private void txtb4_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
            if (e.KeyCode == Keys.Enter)
				SendKeys.Send("{Tab}");
		}

		private void txtb5_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
            if (e.KeyCode == Keys.Enter)
				SendKeys.Send("{Tab}");
		}

		private void txtb6_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
            if (e.KeyCode == Keys.Enter)
				SendKeys.Send("{Tab}");
		}

		private void txtb7_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
            if (e.KeyCode == Keys.Enter)
				SendKeys.Send("{Tab}");
		}

		private void txtb8_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
            if (e.KeyCode == Keys.Enter)
				SendKeys.Send("{Tab}");
		}

		private void txtb9_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
            if (e.KeyCode == Keys.Enter)
				SendKeys.Send("{Tab}");
		}

		private void txtb10_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
            if (e.KeyCode == Keys.Enter)
				SendKeys.Send("{Tab}");
		}

		private void txtb11_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
            if (e.KeyCode == Keys.Enter)
				SendKeys.Send("{Tab}");
		}

		private void txtb12_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
            if (e.KeyCode == Keys.Enter)
				SendKeys.Send("{Tab}");
		}

		private void txtb13_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Enter)
				SendKeys.Send("{Tab},{F4}");
		}
	
		private void update_NgachBac(string mangach,int bac,decimal hs_lc)
		{			
			string sql="update "+m_user+".hopdong set hs_lc="+hs_lc+" where mangach='"+mangach+"' and bac="+bac+"";
			mDB.Execute_data(sql);			
		}
		private bool saveData()
		{
            bool gttv = false;
            try
			{				
									
					string t="";
					string m="",m_m="",loai="",nhomngach="";
					decimal n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,stt;
					n1=0;n2=0;n3=0;n4=0;n5=0;n6=0;n7=0;n8=0;n9=0;n10=0;
                    n11 = 0; n12 = 0; stt = 0;
					if(txtMa.Text.Trim().Length<=7)
					{
						if(txtTen.Text.Trim().Length<=50)
						{	
							if (fthem)
							{
								m_m=txtMa.Text.Trim();
								m=kiemtra_ma(m_m);
							}
							else
							{
								m=txtb13.Text.Trim();
								m_m=txtMa.Text.Trim();
							}
                            if (m == "")
                            {
                                MessageBox.Show(lan.Change_language_MessageText("Yêu cầu nhập mã ngạch công chức!"), AccessData.Msg, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                txtMa.Focus();
                                return false;
                            }
							t=txtTen.Text.Trim();
							n1=(txtb1.Text.Trim()=="")?0:decimal.Parse(txtb1.Text.Trim());							
							n2=(txtb2.Text.Trim()=="")?0:decimal.Parse(txtb2.Text.Trim());							
							n3=(txtb3.Text.Trim()=="")?0:decimal.Parse(txtb3.Text.Trim());							
							n4=(txtb4.Text.Trim()=="")?0:decimal.Parse(txtb4.Text.Trim());							
							n5=(txtb5.Text.Trim()=="")?0:decimal.Parse(txtb5.Text.Trim());							
							n6=(txtb6.Text.Trim()=="")?0:decimal.Parse(txtb6.Text.Trim());							
							n7=(txtb7.Text.Trim()=="")?0:decimal.Parse(txtb7.Text.Trim());							
							n8=(txtb8.Text.Trim()=="")?0:decimal.Parse(txtb8.Text.Trim());							
							n9=(txtb9.Text.Trim()=="")?0:decimal.Parse(txtb9.Text.Trim());	
							n10=(txtb10.Text.Trim()=="")?0:decimal.Parse(txtb10.Text.Trim());							
							n11=(txtb11.Text.Trim()=="")?0:decimal.Parse(txtb11.Text.Trim());							
							n12=(txtb12.Text.Trim()=="")?0:decimal.Parse(txtb12.Text.Trim());					
                            loai = cmbloaicc.SelectedValue.ToString().Trim();
                            nhomngach = cbo_nhomngach.SelectedValue.ToString().Trim();
                            stt = txt_stt.Text.Trim()!="" ? decimal.Parse(txt_stt.Text.Trim()):0;
							gttv= mDB.Insert_DMNGACHCONGCHUC(m,t,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,m_m,loai,nhomngach,stt);
							update_NgachBac(m,1,n1);update_NgachBac(m,5,n5);update_NgachBac(m,9,n9);
							update_NgachBac(m,2,n2);update_NgachBac(m,6,n6);update_NgachBac(m,10,n10);
							update_NgachBac(m,3,n3);update_NgachBac(m,7,n7);update_NgachBac(m,11,n11);
							update_NgachBac(m,4,n4);update_NgachBac(m,8,n8);update_NgachBac(m,12,n12);
		
					}	
					load_datagrid();
				}
                fthem = false;
			}
			catch
			{
				MessageBox.Show(lan.Change_language_MessageText("Dữ liệu không hợp lệ!"),AccessData.Msg);
				load_datagrid();
			}
            return gttv;
		}
		private bool IsNumeric (string strNum)
		{	
			int iNum;
			try
			{
				iNum = int.Parse(strNum);
				return true;
			}
			catch
			{
				return false;
			}
		}
		private void txtb1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if (!IsNumeric(e.KeyChar.ToString()))
				e.Handled = true;
			if(e.KeyChar==8 || e.KeyChar=='.')
				e.Handled=false;
		}

		private void txtb2_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if (!IsNumeric(e.KeyChar.ToString()))
				e.Handled = true;
			if(e.KeyChar==8 || e.KeyChar=='.')
				e.Handled=false;
		}

		private void txtb3_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if (!IsNumeric(e.KeyChar.ToString()))
				e.Handled = true;
			if(e.KeyChar==8 || e.KeyChar=='.')
				e.Handled=false;
		}

		private void txtb4_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if (!IsNumeric(e.KeyChar.ToString()))
				e.Handled = true;
			if(e.KeyChar==8 || e.KeyChar=='.')
				e.Handled=false;
		}

		private void txtb5_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if (!IsNumeric(e.KeyChar.ToString()))
				e.Handled = true;
			if(e.KeyChar==8 || e.KeyChar=='.')
				e.Handled=false;
		}

		private void txtb6_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if (!IsNumeric(e.KeyChar.ToString()))
				e.Handled = true;
			if(e.KeyChar==8 || e.KeyChar=='.')
				e.Handled=false;
		}

		private void txtb7_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if (!IsNumeric(e.KeyChar.ToString()))
				e.Handled = true;
			if(e.KeyChar==8 || e.KeyChar=='.')
				e.Handled=false;
		}

		private void txtb8_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if (!IsNumeric(e.KeyChar.ToString()))
				e.Handled = true;
			if(e.KeyChar==8 || e.KeyChar=='.')
				e.Handled=false;
		}

		private void txtb9_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if (!IsNumeric(e.KeyChar.ToString()))
				e.Handled = true;
			if(e.KeyChar==8 || e.KeyChar=='.')
				e.Handled=false;
		}

		private void txtb10_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if (!IsNumeric(e.KeyChar.ToString()))
				e.Handled = true;
			if(e.KeyChar==8 || e.KeyChar=='.')
				e.Handled=false;
		}

		private void txtb11_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if (!IsNumeric(e.KeyChar.ToString()))
				e.Handled = true;
			if(e.KeyChar==8 || e.KeyChar=='.')
				e.Handled=false;
		}

		private void txtb12_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if (!IsNumeric(e.KeyChar.ToString()))
				e.Handled = true;
			if(e.KeyChar==8 || e.KeyChar=='.')
				e.Handled=false;
		}	

		private void dgrDanhMucNgachCongChuc_CurrentCellChanged(object sender, System.EventArgs e)
		{
			try
			{
				refresh_Text();
			}
			catch{}
		}

		private void btnKetthuc_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

        private void cmbloaicc_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                SendKeys.Send("{Tab}{F4}");                
        }

        private void txtMa_Validated(object sender, EventArgs e)
        {
            string mangach = "";
            mangach = txtMa.Text.Trim();
            if (fthem == true)
            {
                ds = mDB.get_mangach();
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    if (mangach == dr["ma"].ToString())
                    {
                        MessageBox.Show(lan.Change_language_MessageText("Mã ngạch ngày đã có!"),AccessData.Msg, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        txtMa.Focus();
                    }
                }
            }
            else
            {
                ds = mDB.get_data(" select ma from " + mDB.user + ".mangach where ma <> '"+mangach.Trim()+"' order by ma");
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    if (mangach == dr["ma"].ToString())
                    {
                        MessageBox.Show(lan.Change_language_MessageText("Max ngạch ngày đã có!"),AccessData.Msg, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        txtMa.Focus();
                    }
                }
            }
        }

        private void btn_them_Click(object sender, EventArgs e)
        {
            Ena_control(false);
            Ena_textbox(true);
            clear_Text();
            fthem = true;
            txtMa.Focus();
        }

        private void btn_sua_Click(object sender, EventArgs e)
        {
            Ena_control(false);
            Ena_textbox(true);
            fthem = false;
            txtMa.Focus();            
        }

        private void btn_luu_Click(object sender, EventArgs e)
        {
            try
            {
                if (!saveData()) return;
                Ena_control(true);
                Ena_textbox(false);
                btn_them.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void btn_boqua_Click(object sender, EventArgs e)
        {
            Ena_control(true);
            Ena_textbox(false);
            refresh_Text();
            btn_thoat.Focus();
        }

        private void btn_xoa_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dr = MessageBox.Show(lan.Change_language_MessageText("Đồng ý huỷ ngạch công chức này?"), AccessData.Msg, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dr == DialogResult.Yes)
                {
                    DataSet ds1 = new DataSet();
                    mDB.Execute_data("DELETE  FROM " + m_user + ".mangach WHERE ma='" + txtb13.Text.Trim() + "'");
                    load_datagrid();
                    refresh_Text();
                }
            }
            catch
            {
                load_datagrid();
            }		
        }

        private void btn_thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btn_luu_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                btn_them.Focus();
        }

        private void btn_them_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                txtMa.Focus();
        }

        private void btn_sua_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                txtTen.Focus();
        }

        private void cbo_nhomngach_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                SendKeys.Send("{Tab}");
        }

        private void txt_stt_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                btn_luu.Focus();
        }

        private void txt_stt_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!IsNumeric(e.KeyChar.ToString()))
                e.Handled = true;
            if (e.KeyChar == 8)
                e.Handled = false;
        }
	}
}
